﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace bll
{
    public class functionAdd
    {
        functionControl fC = new functionControl();

        public String[] addTimeSheet(int _pId, String _date, String _hours, String _descr, bool _charge, String _cat)
        {
            String[] _msg = fC.checkAddingTimeSheet(_date, _hours, _descr);

            if (_msg[0] != "fail")
            {
                bll.clsTimeSheet newTime = new bll.clsTimeSheet();
                bll.clsTimeSheetCollection myTimeCol = new bll.clsTimeSheetCollection();
                DateTime _d = Convert.ToDateTime(_date);

                newTime.UserID = bll.clsUser.Session;
                newTime.ProjectID = _pId;
                newTime.Date = _d;
                newTime.Hours = Convert.ToInt32(_hours);
                newTime.Description = _descr;
                newTime.Chargeable = _charge;
                newTime.Category = _cat;

                if (myTimeCol.InsertTimeSheet(newTime) == 1)
                {
                    _msg[0] = "Adding the working time (hours: " + _hours + " date: " +
                    Convert.ToDateTime(_date).ToString("yyyy.MM.dd", System.Globalization.CultureInfo.InvariantCulture) +
                    ") successfully!";
                    System.Drawing.Color gr = Color.Green;
                    _msg[1] = gr.ToArgb().ToString();
                }
                else
                {
                    _msg[0] = "Error! Adding the working time (hours: " + _hours + " date: " +
                    Convert.ToDateTime(_date).ToString("yyyy.MM.dd", System.Globalization.CultureInfo.InvariantCulture) +
                                ") failed for the Project!";
                    System.Drawing.Color red = Color.Red;
                    _msg[1] = red.ToArgb().ToString();
                }
            }
            else
            {
                _msg[0] = "";
            }

            return _msg;

        }//addTimeSheet()


        public String[] addNewEmployee(String _title, String _name, String _position, String _hourlyRate, String _pw, String _email)
        {
            String[] _msg = fC.checkNewEmployeeInput(_name, _email, _hourlyRate, _pw);

            if (_msg[0] != "fail")
            {
                bll.clsUser newUser = new bll.clsUser();
                bll.clsUserCollection myUserCol = new bll.clsUserCollection();

                Char.ToUpper(_name[0]);

                newUser.Title = _title;
                newUser.Name = _name;
                newUser.Position = _position;
                newUser.InternalHourlyRate = Convert.ToInt32(_hourlyRate);
                newUser.LoginPw = _pw;
                newUser.Email = _email;

                if (myUserCol.InsertUser(newUser) == 1)
                {
                    _msg[0] = "Adding the new Employee " + _title + " " + _name + " successfully!";
                    System.Drawing.Color gr = Color.Green;
                    _msg[1] = gr.ToArgb().ToString();
                }
                else
                {
                    _msg[0] = "Error! Adding the new Employee " + _title + " " + _name + " failed!";
                    System.Drawing.Color red = Color.Red;
                    _msg[1] = red.ToArgb().ToString();
                }
            }
            else
            {
                _msg[0] = "";
            }
            return _msg;

        }//addNewEmployee()
    }
}